package com.crazyhat.crazyhat.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crazyhat.crazyhat.entity.Recommend;
import com.crazyhat.crazyhat.mapper.RecommendMapper;
import com.crazyhat.crazyhat.service.IRecommendService;

/**
 * <p>
 * 社团相似度推荐表 服务实现类
 * </p>
 *
 * @author crazyhat
 * @since 2024-07-11
 */
@Service
public class RecommendServiceImpl extends ServiceImpl<RecommendMapper, Recommend> implements IRecommendService {

    @Autowired
    private RecommendMapper recommendMapper;

    /**
     * 更新推荐表
     */
    @Override
    public void updateRecommend() {
        //TODO 更新推荐表
    }

    private double getSimilarity(int baseClubId, int targetClubId) {

        //TODO 计算相似度
        return 0;
    }

    /**
     * 计算向量的夹角余弦
     * @param baseClub
     * @param targetClub
     * @return
     */
    private double CosineOfVector(double[] baseClub,double[] targetClub){

        int length=Math.min(baseClub.length, targetClub.length);

        //TODO 计算向量的夹角余弦

        for (int i = 0; i < length; i++) {
            baseClub[i]=baseClub[i]/Math.sqrt(baseClub[i]*baseClub[i]);
            targetClub[i]=targetClub[i]/Math.sqrt(targetClub[i]*targetClub[i]);
        }

        return 0;
    }
}
